/
CountryRegionController.cs
54 lines (48 loc) · 1.83 KB
/
CountryRegionController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.InternalServices
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web;
using System.Web.Http;
using DotNetNuke.Common.Lists;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Web.Api;
[AllowAnonymous]
public class CountryRegionController : DnnApiController
{
[HttpGet]
public HttpResponseMessage Countries()
{
var searchString = (HttpContext.Current.Request.Params["SearchString"] ?? string.Empty).NormalizeString();
var countries = CachedCountryList.GetCountryList(Thread.CurrentThread.CurrentCulture.Name);
return this.Request.CreateResponse(HttpStatusCode.OK, countries.Values.Where(
x => x.NormalizedFullName.IndexOf(searchString, StringComparison.CurrentCulture) > -1).OrderBy(x => x.NormalizedFullName));
}
[HttpGet]
public HttpResponseMessage Regions(int country)
{
List<Region> res = new List<Region>();
foreach (ListEntryInfo r in new ListController().GetListEntryInfoItems("Region").Where(l => l.ParentID == country))
{
res.Add(new Region
{
Text = r.Text,
Value = r.EntryID.ToString(),
});
}
return this.Request.CreateResponse(HttpStatusCode.OK, res.OrderBy(r => r.Text));
}
public struct Region
{
public string Text;
public string Value;
}
}
}